(define-module (staging snort)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages bison)
  #:use-module (gnu packages flex)
  #:use-module (gnu packages libedit)
  #:use-module (gnu packages lua)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages mpi)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages check)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system cmake))

(define-public libdnet
  (let ((commit "56b9635781571ccc87ab6fc74ba334c3fbd755db")
        (revision "1"))
    (package
      (name "libdnet")
      (version (git-version "1.12" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/ofalk/libdnet.git")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "0hyiw8x21xnz5hkpxkrd2cbpnb16awi5bcijshxdslm5f279a3dq"))))
      (build-system gnu-build-system)
      (home-page "https://github.com/dugsong/libdnet")
      (synopsis "Portable interface to low-level networking routines")
      (description
       "libdnet provides a simplified, portable interface to several
low-level networking routines, including network address manipulation,
kernel arp(4) cache and route(4) table lookup and manipulation,
network firewalling, network interface lookup and manipulation, IP
tunnelling, and raw IP packet and Ethernet frame transmission.")
      (license license:bsd-3))))

(define-public libdaq
  (package
    (name "libdaq")
    (version "2.0.6")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://www.snort.org/downloads/snort/daq-"
                                  version ".tar.gz"))
              (sha256
               (base32
                "1w1s4zchr8zr9vvmnld3q57fxrr50n68dp97d5708riyg7vsa7fl"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags
       (list
        (string-append "--with-libpcap-includes=" (assoc-ref %build-inputs "libpcap") "/include")
        (string-append "--with-libpcap-libraries=" (assoc-ref %build-inputs "libpcap") "/lib"))))
    (inputs
     `(("bison" ,bison)
       ("flex" ,flex)
       ("libpcap" ,libpcap)))
    (home-page "https://www.snort.org/")
    (synopsis "Data Acquisition library for packet I/O")
    (description "The DAQ replaces direct calls to libpcap functions
with an abstraction layer that facilitates operation on a variety of
hardware and software interfaces without requiring changes to Snort.
It is possible to select the DAQ type and mode when invoking Snort to
perform pcap readback or inline operation, etc.  The DAQ library may
be useful for other packet processing applications and the modular
nature allows you to build new modules for other platforms.")
    (license license:gpl2+)))

(define-public snort3-libdaq
  (package
    (inherit libdaq)
    (name "snort3-libdaq")
    (version "3.0.0-alpha2")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/snort3/libdaq.git")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "08xb9s2pha88d1pwr8vssmzxsxb278id598mrlyq2gdk95wglib6"))))
    (native-inputs
     `(("autoconf" ,autoconf)
       ("automake" ,automake)
       ("cmocka" ,cmocka)
       ("libtool" ,libtool)
       ("pkg-config" ,pkg-config)))
    (home-page "https://github.com/snort3/libdaq")))

(define-public snort
  (package
    (name "snort")
    (version "2.9.14.1")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://www.snort.org/downloads/snort/snort-"
                                  version ".tar.gz"))
              (sha256
               (base32
                "0bc23r4a44r131jjs9qya46crrgqd371x4x53q6h1kmalffrhwi4"))))
    (build-system gnu-build-system)
    (arguments
     `(#:configure-flags
       (list
        (string-append "--with-dnet-includes=" (assoc-ref %build-inputs "libdnet") "/include")
        (string-append "--with-dnet-libraries=" (assoc-ref %build-inputs "libdnet") "/lib")
        (string-append "--with-libpcap-includes=" (assoc-ref %build-inputs "libpcap") "/include")
        (string-append "--with-libpcap-libraries=" (assoc-ref %build-inputs "libpcap") "/lib"))))
    (inputs
     `(("libdaq" ,libdaq)
       ("pcre" ,pcre)
       ("libpcap" ,libpcap)
       ("libdnet" ,libdnet)))
    (home-page "https://www.snort.org/")
    (synopsis "Data Acquisition library for packet I/O")
    (description "The DAQ replaces direct calls to libpcap functions
with an abstraction layer that facilitates operation on a variety of
hardware and software interfaces without requiring changes to Snort.
It is possible to select the DAQ type and mode when invoking Snort to
perform pcap readback or inline operation, etc.  The DAQ library may
be useful for other packet processing applications and the modular
nature allows you to build new modules for other platforms.")
    (license license:gpl2+)))

(define-public snort3
  (package
    (inherit snort)
    (name "snort3")
    (version "3.0.0-261")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/snort3/snort3.git")
                    (commit version)))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0dslz7lfyblhch5vrp7w3pydmgwcgdvjh746adlzxb2knc8n9jrx"))))
    (build-system cmake-build-system)
    (arguments '(#:tests? #f))
    (inputs
     `(("hwloc:lib" ,hwloc "lib")
       ("pcre" ,pcre)
       ("libdaq" ,snort3-libdaq)
       ("libpcap" ,libpcap)
       ("libdnet" ,libdnet)
       ("luajit" ,luajit)
       ("openssl" ,openssl)
       ("zlib" ,zlib)))
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (home-page "https://github.com/snort3/snort3")))
